package com.yc.store.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yc.store.bean.Goods;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/4/25
 * Email haijunzhou@hnit.edu.cn
 */
public interface GoodsMapper {

    @Select("select * from goods where state=0")
    public List<Goods> selectAll();

    @Select("<script>" +
            "select * from goods" +
            " <where>" +
            " state = 0" +
            "   <if test=' goods.name != null and goods.name!=\"\"'>and name like concat('%',#{goods.name},'%')</if>" +
            "   <if test=' goods.type != null and goods.type!=\"\"'>and type = #{goods.type}</if>" +
            " </where>" +
            "</script>")
    public List<Goods> select(@Param("goods") Goods goods, IPage<Goods> page);

    @Select("select count(*) from goods where name = #{name} and state = 0")
    public int countByName(String name);

    @Insert("insert into goods values(default,#{name},#{type},0,#{price},default)")
    public void insert(Goods goods);

    @Select("select distinct type from goods where state = 0")
    public List<Goods> selectTypes();

    @Delete("delete from goods where id = #{id}")
    public void deleteById(int id);

    @Delete("update goods set state=1 where id = #{id}")
    public void removeById(int id);

    @Select("select * from goods where state=0 and id=#{id}")
    public Goods selectById(String id);

    /*修改商品信息*/
    @Update("update goods set name=#{name},type=#{type},nums=#{nums},price=#{price} where id=#{id}")
    public void updateGoods(Goods goods);

    @Select("select count(*) from goods where name = #{name} and state = 0 and id !=#{id}")
    public int countByNameExceptSelf(Goods goods);
}
